package com.kukbab.c2dm;

import android.content.*;
import android.preference.*;
import android.util.*;

public class PreferenceMgr {
    SharedPreferences prefs;
    SharedPreferences.Editor editor;
    private Context mContext;
   public static final String REGISTRATION_KEY = "registration_key";
    
   public static PreferenceMgr instance;
    
    private PreferenceMgr(Context context){
     mContext = context;
     prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
     editor =PreferenceManager.getDefaultSharedPreferences(mContext).edit();
    }
   
    public static PreferenceMgr getInstance(Context context){
    	if(instance == null) instance = new PreferenceMgr(context);
    	return instance;
    }
    
    public void removeData(String key){
        Log.d("","removeData ===>>"+key);
        editor.remove("menuId");
        editor.commit();
    }   
   
    public boolean setData(String key, boolean val){    
        try{
        editor.putBoolean(key, val);
        editor.commit();
        Log.d("", "setData>> key :"+key +", defaultVal :" + val);

        return true;
        }catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
   
    public boolean setData(String key, String val){    
        try{
            editor.putString(key, val);
            editor.commit();
            Log.d("","setData>> key :"+key +", defaultVal :" + val);
            return true;
        }catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
   
    public boolean setData(String key, int val){    
    	try{
    		editor.putInt(key, val);
    		editor.commit();
    		Log.d("", "setData>> key :"+key +", val :" + val);
    		return true;
    	}catch (Exception e) {
    		e.printStackTrace();
    		return false;
    	}
    }
    
    public int getData(String key, int defaultVal){    
    	Log.d("","getData>>"+key +"==>>"+prefs.getInt(key,defaultVal));
    	return prefs.getInt(key,defaultVal);
    }
   
    public boolean getData(String key, boolean defaultVal){    
    	Log.d("","getData>>"+key +"==>>"+ prefs.getBoolean(key,defaultVal));
    	return prefs.getBoolean(key,defaultVal);
    }
   
    public String getData(String key, String defaultVal){    
    	Log.d("","getData>>"+key +"===>>"+prefs.getString(key,defaultVal));
    	return prefs.getString(key,defaultVal);
    }    
}
